package service;

import bean.DormAdmin;
import bean.Student;
import dao.AdminDao;
import dao.StudentDao;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

public class DormadminService  {
    /**
     * 用户登录成功
     * @param request
     * @param response
     * @param username
     * @param password
     * @return
     */
    public boolean login(HttpServletRequest request,HttpServletResponse response,String username,String password){
        //封装对象
        DormAdmin dormAdmin=new DormAdmin();
        dormAdmin.setUsername(username);
        dormAdmin.setPassword(password);
        //数据库操作
        AdminDao adminDao=new AdminDao();
        DormAdmin login = adminDao.Login(dormAdmin);
        String dormadminname = dormAdmin.getDormadminname();
        //查询学生所有信息
        ArrayList<Student> studentInfo = adminDao.getStudentInfo();

        //存入session
        boolean flag=login==null?false:true;
        if (flag){
            System.out.println("登录成功");
            request.getSession().setAttribute("dormadmin",dormAdmin);
            request.getSession().setAttribute("dormadminname",dormadminname);
            request.getSession().setAttribute("studentInfo",studentInfo);

        }
        return flag;
    }
}
